home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13683 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: prodigy.com!usenet
  2. From: XKWR65B@prodigy.com (Mark Rubelmann)
  3. Newsgroups: comp.lang.c++
  4. Subject: How do you return values from in-line asm?
  5. Date: 26 Mar 1996 21:07:23 GMT
  6. Organization: Prodigy Services Company  1-800-PRODIGY
  7. Distribution: world
  8. Message-ID: <4j9mab$19si@usenetp1.news.prodigy.com>
  9. NNTP-Posting-Host: innugap8-int.news.prodigy.com
  10. X-Newsreader: Version 1.2
  11.  
  12.  
  13. Hey there! I got this book that is about programming games in C but I 
  14. have Borland C++ v3.0 and some of the stuff doesn't work quite right. 
  15. Most of the things I have been able to figure out on my own but I'm 
  16. having trouble returning values from an inline assembly function. Here's 
  17. the code that's in the book:
  18.  
  19. unsigned char Get_Scan_Code(void)
  20. {
  21. asm {
  22.      mov ah,01h        //Function 1: is a key ready?
  23.      int 16h                // Call interrupt
  24.      jz empty             // No key, exit
  25.      mov ah,00h        // Function 0: get scan code
  26.      int 16h                // Call interrupt
  27.      mov al,ah           // result was in ah so put it in al
  28.      xor ah,ah            // zero out ah
  29.      jmp done            // the data's in ax    (??? ax???)
  30.      
  31. empty:
  32.      xor ax,ax            // clear out ax, 0 means no key
  33. done:
  34.      }
  35. }
  36.  
  37.  
  38. First of all, I just don't understand how the resut went from al to ax. 
  39. Also, I know the line labels should be outside of the asm statement but 
  40. that's the way it was in the book. I've tried fooling around with ret and 
  41. stuff like that but I can't get it to work. The compiler always gives a 
  42. warning that it should return a value. When I try to use the function in 
  43. something like:
  44.  
  45.      while(Get_Scan_Code==0) {}
  46.  
  47. but it doesn't work, it just goes on to the next statement. Any help 
  48. would be appreciated.
  49.  
  50.  
  51.